<template>
  <div class="mod-config">
    <el-button type="primary" @click="goback()" style="margin-bottom: 20px;">返回</el-button>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
    >
      <el-table-column prop="saveTime" header-align="center" align="center" label="日期"></el-table-column>
      <el-table-column prop="bookName" header-align="center" align="center" label="学习书籍"></el-table-column>
      <el-table-column prop="chapterName" header-align="center" align="center" label="学习章节"></el-table-column>
      <el-table-column prop="readingTime" header-align="center" align="center" label="存储的听书时间/秒"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <!--新增/修改e-->

  </div>
</template>

<script>
  import StudyRecord from './studyRecord'
  export default {
    data() {
      return {
        id: '',
        isAdd: true,
        visible1: false,
        member: true,
        dataForm1: {
          isFinishPlan: ''
        },
        dataForm: {
          reviewState: null,
          isPublic: '1',
          label: null
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        showDatePicker: false,
        readingTime: '',
        dateTime:''
      }
    },
    components: {
      StudyRecord,
    },
    watch: {
      // 如果 `question` 发生改变，这个函数就会运行
      readingTime: function (newQuestion, oldQuestion) {
        this.dataForm1.readingTime = newQuestion
        if(newQuestion>=20) {
          this.dataForm1.isFinishPlan = 1
        } else {
          this.dataForm1.isFinishPlan = 0
        }
      }
    },
    mounted() {
    },
    methods: {
      // 获取数据列表
      getDataList(id, dateTime) {
        this.dataListLoading = true
        if(id) {
          this.userId = id
          this.dateTime = dateTime
        }
        // this.dataListLoading = true
        let obj = {
          page: this.pageIndex,
          limit: this.pageSize,
        };
        obj.userId = this.userId
        obj.dateTime = this.dateTime
        this.$http({
          url: this.$http.adornUrl('/course/studydurationstatistics/readingTime/list'),
          method: 'get',
          params: this.$http.adornParams(obj)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      goback() {
        this.$emit('goBack')
      }
    }
  }
</script>
<style>
  .margin_10{
    margin-bottom: 10px;
  }
  .text_r{
    text-align: right;
    padding-right: 15px;
  }
  .inineBlock{
    display: inline-block;
  }
  img{
    width: 100%;
    height: auto;
  }
  .imgList{
    display: flex;
    flex-wrap: wrap;
  }
  .imgList>div{
    width: 80px;
    margin: 5px 15px 5px 0;
  }
</style>
